/*
 * Copyright 2004-2011 Paolo Conte
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jellylab.ojoverse.types;

import java.math.BigDecimal;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Blob;
import java.sql.Types;

public class Datatypes {

    public static final int NULL = 0;
	public static final int BIT = 1;    // Types.BIT
	public static final int BYTE = 2;
	public static final int INTEGER = 4;
	public static final int SHORTINT = 8;
	public static final int BIGINT = 16;
	public static final int PICOINT = 32;
	public static final int FLOAT = 64;
	public static final int REAL = 126;		//FLOAT
	public static final int DOUBLE = 256;
	public static final int DECIMAL = 512;
	public static final int DATE = 1024;
	public static final int TIME = 2048;
	public static final int DATETIME = 4096;
	public static final int TIMESTAMP = 8192;
	public static final int CHAR = 16384;
	public static final int VARCHAR = 32768;
	public static final int TEXT = 65536;
	public static final int BINARY = 131072;
	public static final int BLOB = 262144;
    public static final int OBJECT = 524288;
    public static final int CUSTOM = 1048576;

	public static Class mapDatatype(int datatype) {
		switch (datatype) {
			case BIT:
				return Boolean.class;
			case BYTE:
			case SHORTINT:
				return Byte.class;
			case INTEGER:
				return Integer.class;
			case BIGINT:
				return Long.class;
			case FLOAT:
			case REAL:
				return Float.class;
			case DOUBLE:
				return Double.class;
			case DECIMAL:
				return BigDecimal.class;
			case DATE:
			case DATETIME:
				return Date.class;
			case TIME:
				return Time.class;
			case TIMESTAMP:
				return Timestamp.class;
			case CHAR:
			case VARCHAR:
			case TEXT:
				return String.class;
			case BINARY:
				return String.class;	// TODO: verify other options: java.sql.Blob or byte[]
			case BLOB:
				return Blob.class;
			default:
				return null;
		}
	}
	/*
    // only for JDK >= 1.7
	public static Class mapDatatype(String datatype) {
		switch (datatype.toUpperCase()) {
			case "BIT":
				return Boolean.class;
			case "BYTE":
			case "SHORTINT":
				return Byte.class;
			case "INTEGER":
				return Integer.class;
			case "BIGINT":
				return Long.class;
			case "FLOAT":
			case "REAL":
				return Float.class;
			case "DOUBLE":
				return Double.class;
			case "DECIMAL":
				return BigDecimal.class;
			case "DATE":
			case "DATETIME":
				return Date.class;
			case "TIME":
				return Time.class;
			case "TIMESTAMP":
				return Timestamp.class;
			case "CHAR":
			case "VARCHAR":
				return String.class;
			case "TEXT":
				return String.class;
			case "BINARY":
				return String.class;	// TODO: verify other options: java.sql.Blob or byte[]
			case "BLOB":
				return Blob.class;
			default:
				return null;
		}
	}
     */
	/*
	public static boolean isDatatype(int colDatatype, int datatype)
	{
		return (colDatatype & datatype) > 0;
	}
    */
}
